import 'package:flutter/material.dart';
import 'package:Sayagh/tablepress/csv.dart';
import 'package:Sayagh/tablepress/goods/Goods.dart';
import 'package:Sayagh/i18n/i18nLocale.dart';
import 'package:Sayagh/Configs.dart';

class Categories extends StatefulWidget {
  final String _url;
  final String _tableName;
  final String _citeName;
  Categories(this._url,this._tableName,this._citeName);
  @override
  State<StatefulWidget> createState() {
    return _Categories();
  }
}
class _Categories extends State<Categories> {
  @override
  Widget build(BuildContext context) {
    String categoriesUrl = "${widget._url}/wp-content/tables/${widget._tableName}.csv";
    Future<List<List>> categoriesList = csv(categoriesUrl);

    return Scaffold(
    appBar: AppBar(title: Text(widget._citeName,textAlign: TextAlign.center,),centerTitle: true,),
//      appBar: AppBar(title: Text(i18nLocale[ourLocale]['categories']),),
      body: FutureBuilder(
        future: categoriesList,
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.data == null) {
            return Card(
              child: Text(i18nLocale[ourLocale]['reciving']),
            );
          }
          else {
            return ListView.builder(
                itemCount: snapshot.data[1].length - 1,
                itemBuilder: (BuildContext context, int index) {
                  List<String> _categories = snapshot.data[1][index];

                  Color color = Colors.greenAccent;
                  if (index % 2 == 0) {
                    color = Colors.lightGreen;
                  }
                  return Card(
                      color: color,
                      child:InkWell(child: Text(_categories[1],textDirection: TextDirection.rtl,textAlign: TextAlign.center,),
                      onTap: ()=> Navigator.push(context, MaterialPageRoute(builder: (context) => (Goods(_categories[3], _categories[2],_categories[1])))),
                      )
                  );
                }
            );
          }
        },
      ),
    );
  }
}